<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class AdminController extends Controller
{
   //本周起止时间unix时间戳
   private $week_start;
   private $week_end;

   //本月起止时间unix时间戳
   private $month_start;
   private $month_end;

   /**
    * Create a new controller instance.
    *
    * @return void
    */
   public function __construct()
   {
//      $this->middleware('auth.admin:admin');
      $this->week_start = mktime(0, 0, 0, date("m"), date("d") - date("w") + 1, date("Y"));
      $this->week_end = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y"));

      $this->month_start = mktime(0, 0, 0, date("m"), 1, date("Y"));
      $this->month_end = mktime(23, 59, 59, date("m"), date("t"), date("Y"));
   }

   /**
    * Show the application dashboard.
    *
    * @return \Illuminate\Http\Response
    */
   public function index()
   {
//      dd('后台首页，当前用户名：' . auth('admin')->user()->name);
      return view('admin.index');
   }

   /***
    *  统计性别
    */
   public function sex_total()
   {
      $data = [
         ['性别' => '男', '人数' => DB::table('users')->where('sex', 1)->count()],
         ['性别' => '女', '人数' => DB::table('users')->where('sex', 0)->count()],
      ];

      return response()->json($data);
   }

   /**
    * 清除缓存
    */
   public function destroy()
   {
      Cache::flush();
   }
}